﻿Imports BusinessRule.IBusiness
Imports BusinessRule.BusinessFactory
Imports BusinessRule.DTO
Imports BusinessRule.Common

Partial Class wucCheckPointResultInput
    Inherits System.Web.UI.UserControl

    Private oIBusiness As uMESCheckPointManageIBusiness = uMESBusinessFactory.instance.GetCheckPointManageObject()

    ''' <summary>
    ''' 检测项录入列表控件
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property wgdCheckPointInfo() As Camstar.WebClient.FormsBuilder.WebGridControls.WebGrid
        Get
            Return wgdCheckPoint
        End Get
        Set(ByVal value As Camstar.WebClient.FormsBuilder.WebGridControls.WebGrid)
            wgdCheckPoint = value
        End Set
    End Property

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Try
          
        Catch ex As Exception
            lblMessage.Text = ex.Message
        End Try
    End Sub

    Protected Sub btnSelectProductNo_Click(sender As Object, e As System.EventArgs) Handles btnSelectProductNo.Click
        Try
            lblMessage.Text = ""
            If lstAllProductNo.ListControl.Items.Count = 0 Then
                lblMessage.Text = "待选择零件序号列表为空"
                Exit Sub
            End If
            If lstAllProductNo.ListControl.SelectedIndex = -1 Then
                lblMessage.Text = "请选择要添加的零件序号"
                Exit Sub
            End If

            For i = lstAllProductNo.ListControl.Items.Count - 1 To 0 Step -1
                If lstAllProductNo.ListControl.Items(i).Selected = True Then
                    If wgdCheckPoint.Rows.Count > 0 Then
                        Dim intCount As Integer = 0
                        For j = 0 To wgdCheckPoint.Rows.Count - 1
                            If wgdCheckPoint.Rows(j).Cells.FromKey("ProductNo").Text = lstAllProductNo.ListControl.Items(i).Value Then
                                wgdCheckPoint.Rows(j).Hidden = False
                                intCount = intCount + 1
                            End If
                        Next
                        If intCount > 0 Then
                            lstAllProductNo.ListControl.Items.RemoveAt(i)
                        End If
                    Else
                        lblMessage.Text = "缺少检测项内容"
                        Exit Sub
                    End If
                End If
            Next
        Catch ex As Exception
            lblMessage.Text = ex.Message
        End Try
    End Sub

    Protected Sub btnUnSelectProductNo_Click(sender As Object, e As System.EventArgs) Handles btnUnSelectProductNo.Click
        Try
            lblMessage.Text = wgdCheckPoint.Rows.Count
            Exit Sub
            lblMessage.Text = ""
            Dim temCell As Infragistics.WebUI.UltraWebGrid.TemplatedColumn = wgdCheckPoint.Bands(0).Columns(0)
            For i = 0 To wgdCheckPoint.Rows.Count - 1
                Dim chkSelect As CheckBox = temCell.CellItems(i).FindControl("chkSelect")
                If chkSelect.Checked = True Then
                    wgdCheckPoint.Rows(i).Hidden = True
                    Dim strProductNo As String
                    strProductNo = wgdCheckPoint.Rows(i).Cells.FromKey("ProductNo").Text
                    For j = 0 To wgdCheckPoint.Rows.Count - 1
                        If strProductNo = wgdCheckPoint.Rows(j).Cells.FromKey("ProductNo").Text Then
                            wgdCheckPoint.Rows(j).Hidden = True
                        End If
                    Next
                    Dim boolExist As Boolean = False

                    For j = 0 To lstAllProductNo.ListControl.Items.Count - 1
                        If lstAllProductNo.ListControl.Items(i).Value = strProductNo Then
                            boolExist = True
                            Exit For
                        End If
                    Next
                    If boolExist = False Then
                        Dim strValue As String = wgdCheckPoint.Rows(i).Cells.FromKey("ProductNo").Text
                        Dim strText As String = strValue.Replace("", "")
                        lstAllProductNo.ListControl.Items.Add(wgdCheckPoint.Rows(i).Cells.FromKey("ProductNo").Text)
                    End If
                End If
            Next
        Catch ex As Exception
            lblMessage.Text = ex.Message
        End Try
    End Sub

    '查询检测项信息
    Public Sub LoadCheckPointInfo(ByVal oQuery As Dictionary(Of String, String), ByVal intInputType As Integer, ByVal strContainerName As String)
        Try
            lblMessage.Text = ""
            If intInputType = 1 Then
                wgdCheckPointInfo.Bands(1).Columns(3).Hidden = True
                wgdCheckPointInfo.Bands(1).Columns(4).Hidden = True
                wgdCheckPointInfo.Bands(1).Columns(1).AllowUpdate = Infragistics.WebUI.UltraWebGrid.AllowUpdate.Yes
            Else
                wgdCheckPointInfo.Bands(1).Columns(3).Hidden = False
                wgdCheckPointInfo.Bands(1).Columns(4).Hidden = False
                wgdCheckPointInfo.Bands(1).Columns(1).AllowUpdate = Infragistics.WebUI.UltraWebGrid.AllowUpdate.No
            End If
            Dim oResult As New uMESProcessResult
            oResult = oIBusiness.GetCheckPointInfoForCheck(oQuery)
            If oResult.Result = True Then
                Dim ds As New DataSet
                ds = oResult.DBDataSet

                If IsNothing(ds) = False Then
                    If ds.Tables.Count > 0 Then

                        Dim dtContainerChildTemp As New DataTable
                        dtContainerChildTemp = ds.Tables("dtContainerChildTemp")
                        lstAllProductNo.ListControl.DataSource = dtContainerChildTemp
                        lstAllProductNo.ListControl.DataTextField = "ProductNoDesc"
                        lstAllProductNo.ListControl.DataValueField = "ProductNo"
                        lstAllProductNo.ListControl.DataBind()
                        ds.Tables.Remove("dtContainerAllChild")
                        ds.Tables.Remove("dtCheckPointInfo")
                        ds.Tables.Remove("dtContainerChildTemp")

                        Dim dt As New DataTable

                        dt = ds.Tables("dtMain")

                        Dim dtImageAll As DataTable
                        Session("dtImage") = dtImageAll
                        If dt.Rows.Count > 0 Then
                            Dim strCode As String = ""
                            For i = 0 To dt.Rows.Count - 1
                                If dt.Rows(i).IsNull("Checkpointnote") = False Then
                                    Dim strCheckPointNote, strCheckPointCode As String
                                    dtImageAll = Session("dtImage")
                                    strCheckPointNote = dt.Rows(i).Item("Checkpointnote")
                                    Dim strPagePath As String
                                    strPagePath = System.Web.HttpContext.Current.Request.Path

                                    strCheckPointCode = DataAdjust.ParseCode(strCheckPointNote, strPagePath, dtImageAll)
                                    Session("dtImage") = dtImageAll.Copy
                                    dt.Rows(i).Item("CheckPointDisp") = strCheckPointCode
                                    If strCode = "" Then
                                        strCode = strCheckPointCode
                                    End If
                                End If
                            Next
                        End If
                    End If
                End If

                wgdCheckPointInfo.DataSource = ds
                wgdCheckPointInfo.DataBind()

                ''显示时去掉零件编号前的批次号
                'For i As Integer = 0 To wgdCheckPointInfo.Rows.Count - 1
                '    Dim strProductNo As String = wgdCheckPointInfo.Rows(i).Cells.FromKey("ProductNo").Text
                '    wgdCheckPointInfo.Rows(i).Cells.FromKey("ProductNoDesc").Text = strProductNo.Replace(strContainerName & "-", "")
                'Next

                If wgdCheckPointInfo.Rows.Count > 0 Then
                    Dim temCell As Infragistics.WebUI.UltraWebGrid.TemplatedColumn = wgdCheckPointInfo.Bands(0).Columns(0)
                    For i = 0 To wgdCheckPointInfo.Rows.Count - 1
                        Dim strResultNum As String
                        Dim intResultNum As Integer
                        strResultNum = wgdCheckPointInfo.Rows(i).Cells.FromKey("ResultNum").Text.Trim
                        If IsNumeric(strResultNum) = True Then
                            intResultNum = CInt(strResultNum)
                        Else
                            intResultNum = 0
                        End If

                        Dim chkSelect As CheckBox = temCell.CellItems(i).FindControl("chkSelect")
                        'chkSelect.Enabled = False

                        ''If intResultNum = 0 Then
                        '    wgdCheckPointInfo.Rows(i).Hidden = True
                        'Else
                        '    Dim chkSelect As CheckBox = temCell.CellItems(i).FindControl("chkSelect")
                        '    chkSelect.Enabled = False
                        'End If
                    Next
                End If
            Else
                lblMessage.Text = oResult.Message
            End If
        Catch ex As Exception
            lblMessage.Text = ex.Message
        End Try
    End Sub
End Class
